package com.maozzi.passport.web.controller.rest;

import com.maozzi.api.user.UserService;
import com.maozzi.api.user.model.TokenDTO;
import com.maozzi.common.model.ResultVO;
import com.maozzi.passport.web.model.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 管理员 controller
 *
 * @author maozi
 */
@Slf4j
@RestController
@RequestMapping("/rest/admin")
public class AdminController {
    @Resource
    private UserService userService;

    @PostMapping("/login.json")
    public ResultVO<String> login(@RequestBody UserVO vo) {
        // 登录
        TokenDTO tokenDTO = userService.signIn(vo.getName(), vo.getPassword());

        ResultVO<String> resultVO = ResultVO.success();
        resultVO.setData(tokenDTO.getToken());

        return resultVO;
    }

}
